# dish.r
# Base on a problem from "Digital Dice" by Paul J. Nahin
# Problem 1: The Clumsy Dishwasher Problem
# From p.37
# Use a simulation to estimate the probability that a particular
# dishwasher at a restaurant breaks at least four of the five
# broken dishes in a week, assuming all five dishwashers at the restaurant
# have same probability of breaking a dish.

#this is the solution provided by the author in the second half of the book

clumsy <- 0
for (k in 1:1000000)
{
	brokendishes <- 0
	for (j in 1:5)
	{
		r <- runif(1)
		if (r < 0.2) brokendishes <- brokendishes + 1
	}
	
	if (brokendishes > 3) clumsy = clumsy + 1
}

print(clumsy/1000000)

